package com.openbravo.pos.payment;

import com.openbravo.data.gui.MessageInf;
import com.openbravo.editor.JEditorCurrencyPositive;
import com.openbravo.editor.JEditorKeys;
import com.openbravo.format.Formats;
import com.openbravo.pos.customers.CustomerInfoExt;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.DataLogicSystem;
import com.openbravo.pos.scripting.ScriptEngine;
import com.openbravo.pos.scripting.ScriptException;
import com.openbravo.pos.scripting.ScriptFactory;
import com.openbravo.pos.util.RoundUtils;
import com.openbravo.pos.util.ThumbNailBuilder;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;

public class JPaymentCashPos extends JPanel
  implements JPaymentInterface
{
  private JPaymentNotifier m_notifier;
  private double m_dPaid;
  private double m_dTotal;
  private JLabel jLabel6;
  private JLabel jLabel8;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JPanel jPanel3;
  private JPanel jPanel4;
  private JPanel jPanel5;
  private JPanel jPanel6;
  private JLabel m_jChangeEuros;
  private JEditorKeys m_jKeys;
  private JLabel m_jMoneyEuros;
  private JEditorCurrencyPositive m_jTendered;

  public JPaymentCashPos(JPaymentNotifier paramJPaymentNotifier, DataLogicSystem paramDataLogicSystem)
  {
    this.m_notifier = paramJPaymentNotifier;
    initComponents();
    this.m_jTendered.addPropertyChangeListener("Edition", new RecalculateState( ));
    this.m_jTendered.addEditorKeys(this.m_jKeys);
    String str = paramDataLogicSystem.getResourceAsXML("payment.cash");
    if (str != null)
      try
      {
        ScriptEngine localScriptEngine = ScriptFactory.getScriptEngine("beanshell");
        localScriptEngine.put("payment", new ScriptPaymentCash(paramDataLogicSystem));
        localScriptEngine.eval(str);
      }
      catch (ScriptException localScriptException)
      {
        MessageInf localMessageInf = new MessageInf(-67108864, AppLocal.getIntString("message.cannotexecute"), localScriptException);
        localMessageInf.show(this);
      }
  }

  public void activate(CustomerInfoExt paramCustomerInfoExt, double paramDouble, String paramString)
  {
    this.m_dTotal = paramDouble;
    this.m_jTendered.reset();
    this.m_jTendered.activate();
    printState();
  }

  public PaymentInfo executePayment()
  {
    if (this.m_dPaid - this.m_dTotal >= 0.0D)
      return new PaymentInfoCash(this.m_dTotal, this.m_dPaid);
    return new PaymentInfoCash(this.m_dPaid, this.m_dPaid);
  }

  public Component getComponent()
  {
    return this;
  }

  private void printState()
  {
    Double localDouble = this.m_jTendered.getDoubleValue();
    if ((localDouble == null) || (localDouble.doubleValue() == 0.0D))
      this.m_dPaid = this.m_dTotal;
    else
      this.m_dPaid = localDouble.doubleValue();
    int i = RoundUtils.compare(this.m_dPaid, this.m_dTotal);
    this.m_jMoneyEuros.setText(Formats.CURRENCY.formatValue(new Double(this.m_dPaid)));
    this.m_jChangeEuros.setText(i > 0 ? Formats.CURRENCY.formatValue(new Double(this.m_dPaid - this.m_dTotal)) : null);
    this.m_notifier.setStatus(this.m_dPaid > 0.0D, i >= 0);
  }

  private void initComponents()
  {
    this.jPanel5 = new JPanel();
    this.jPanel4 = new JPanel();
    this.m_jChangeEuros = new JLabel();
    this.jLabel6 = new JLabel();
    this.jLabel8 = new JLabel();
    this.m_jMoneyEuros = new JLabel();
    this.jPanel6 = new JPanel();
    this.jPanel2 = new JPanel();
    this.jPanel1 = new JPanel();
    this.m_jKeys = new JEditorKeys();
    this.jPanel3 = new JPanel();
    this.m_jTendered = new JEditorCurrencyPositive();
    setLayout(new BorderLayout());
    this.jPanel5.setLayout(new BorderLayout());
    this.jPanel4.setPreferredSize(new Dimension(0, 100));
    this.jPanel4.setLayout(null);
    this.m_jChangeEuros.setBackground(Color.white);
    this.m_jChangeEuros.setHorizontalAlignment(4);
    this.m_jChangeEuros.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(UIManager.getDefaults().getColor("Button.darkShadow")), BorderFactory.createEmptyBorder(1, 4, 1, 4)));
    this.m_jChangeEuros.setOpaque(true);
    this.m_jChangeEuros.setPreferredSize(new Dimension(150, 25));
    this.jPanel4.add(this.m_jChangeEuros);
    this.m_jChangeEuros.setBounds(120, 50, 150, 25);
    this.jLabel6.setText(AppLocal.getIntString("Label.ChangeCash"));
    this.jPanel4.add(this.jLabel6);
    this.jLabel6.setBounds(20, 50, 100, 15);
    this.jLabel8.setText(AppLocal.getIntString("Label.InputCash"));
    this.jPanel4.add(this.jLabel8);
    this.jLabel8.setBounds(20, 20, 100, 15);
    this.m_jMoneyEuros.setBackground(new Color(153, 153, 255));
    this.m_jMoneyEuros.setHorizontalAlignment(4);
    this.m_jMoneyEuros.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(UIManager.getDefaults().getColor("Button.darkShadow")), BorderFactory.createEmptyBorder(1, 4, 1, 4)));
    this.m_jMoneyEuros.setOpaque(true);
    this.m_jMoneyEuros.setPreferredSize(new Dimension(150, 25));
    this.jPanel4.add(this.m_jMoneyEuros);
    this.m_jMoneyEuros.setBounds(120, 20, 150, 25);
    this.jPanel5.add(this.jPanel4, "North");
    this.jPanel6.setLayout(new FlowLayout(0));
    this.jPanel5.add(this.jPanel6, "Center");
    add(this.jPanel5, "Center");
    this.jPanel2.setLayout(new BorderLayout());
    this.jPanel1.setLayout(new BoxLayout(this.jPanel1, 1));
    this.jPanel1.add(this.m_jKeys);
    this.jPanel3.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.jPanel3.setLayout(new BorderLayout());
    this.jPanel3.add(this.m_jTendered, "Center");
    this.jPanel1.add(this.jPanel3);
    this.jPanel2.add(this.jPanel1, "North");
    add(this.jPanel2, "After");
  }

  private class AddAmount
    implements ActionListener
  {
    private double amount;

    public AddAmount(double arg2)
    {
      Object localObject;
      this.amount = arg2;
    }

    public void actionPerformed(ActionEvent paramActionEvent)
    {
      Double localDouble = JPaymentCashPos.this.m_jTendered.getDoubleValue();
      if (localDouble == null)
        JPaymentCashPos.this.m_jTendered.setDoubleValue(Double.valueOf(this.amount));
      else
        JPaymentCashPos.this.m_jTendered.setDoubleValue(Double.valueOf(localDouble.doubleValue() + this.amount));
      JPaymentCashPos.this.printState();
    }
  }

  public class ScriptPaymentCash
  {
    private DataLogicSystem dlSystem;
    private ThumbNailBuilder tnbbutton;

    public ScriptPaymentCash(DataLogicSystem arg2)
    {
      Object localObject;
      this.dlSystem = arg2;
      this.tnbbutton = new ThumbNailBuilder(64, 54, "com/openbravo/images/cash.png");
    }

    public void addButton(String paramString, double paramDouble)
    {
      JButton localJButton = new JButton();
      localJButton.setIcon(new ImageIcon(this.tnbbutton.getThumbNailText(this.dlSystem.getResourceAsImage(paramString), Formats.CURRENCY.formatValue(Double.valueOf(paramDouble)))));
      localJButton.setFocusPainted(false);
      localJButton.setFocusable(false);
      localJButton.setRequestFocusEnabled(false);
      localJButton.setHorizontalTextPosition(0);
      localJButton.setVerticalTextPosition(3);
      localJButton.setMargin(new Insets(2, 2, 2, 2));
      localJButton.addActionListener(new JPaymentCashPos.AddAmount( paramDouble));
      JPaymentCashPos.this.jPanel6.add(localJButton);
    }
  }

  private class RecalculateState
    implements PropertyChangeListener
  {
    private RecalculateState()
    {
    }

    public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent)
    {
      JPaymentCashPos.this.printState();
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.payment.JPaymentCashPos
 * JD-Core Version:    0.6.0
 */